import requests
from config import RunConfig

'''
任务管理-院任务计划
'''
def create(para):
    '''
    创建项目
    :param para: {
                    "projectTypeId": "",
                    "base": "",
                    "projectCode": "",
                    "terrainLevel": "",
                    "projectName": "广州白云站站房详勘",  # 项目名，必填项
                    "stageId": "",
                    "mainProjectId": "",
                    "assignmentFile": "[]",
                    "property": 2, # 管控类型 1或者2，必填项
                    "workloadList": [   # 计划工作量，必填项，至少有一条
                        {
                            "methodId": 1,
                            "meaUnit": "km-点",
                            "isDouble": 1,
                            "workload1": "1",
                            "workload2": "10"
                        }
                    ]
                }
    :return:
    '''
    response = requests.post(
        url = RunConfig.url + "/plan/assignment/create",
        headers = RunConfig.headers,
        json=para,
        verify = False
    )
    return response


def update(para):
    '''
    修改院计划任务书
    :param para: {
        "projectTypeId": "",
        "base": "asdbc",
        "projectCode": "",
        "terrainLevel": "",
        "projectName": "广州白云站站房详勘",
        "stageId": "",
        "mainProjectId": "",
        "assignmentFile": "[]",
        "property": 2,
        "workloadList": [
            {
                "methodId": 1,
                "meaUnit": "km-点",
                "isDouble": 1,
                "workload1": "1",
                "workload2": "10"
            }
        ]
    }
    :return:
    '''
    response = requests.post(
        url = RunConfig.url + "/plan/assignment/update",
        headers = RunConfig.headers,
        json=para,
        verify = False
    )
    return response


def delete(para):
    '''
    院计划任务书删除
    :param para: {
      "projectId": 152 # 项目id
    }
    :return:
    '''
    response = requests.post(
        url = RunConfig.url + "/plan/assignment/delete/{}".format(para['projectId']),
        headers = RunConfig.headers,
        json = {},
        verify = False
    )
    return response


def search(project_name, base, property):
    '''
    分页查询院计划任务书
    :param project_name:
    :param base:
    :param property:
    :return:
    '''
    response = requests.post(
        url=RunConfig.url + "/plan/assignment/page?page=1&perPage=10",
        headers=RunConfig.headers,
        json={
            'projectName': project_name,
            'base': base,
            'property': property
        },
        verify=False
    )
    return response


def info(id):
    '''
    院计划任务书详情
    :param id:
    :return:
    '''
    response = requests.post(
        url=RunConfig.url + "/plan/assignment/info/{}".format(id),
        headers=RunConfig.headers,
        json={},
        verify=False
    )
    return response
